home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / Harvest C / MPW Int & Lib / Interfaces / StdIO.h < prev    next >
Text File  |  1991-04-17  |  6KB  |  264 lines

  1. /************************************************************
  2.  
  3.     StdIO.h
  4.     Input / output
  5.     
  6.     Copyright © Apple Computer,Inc.  1985-1990.
  7.  
  8.     Copyright American Telephone & Telegraph
  9.     Used with permission, Apple Computer Inc. (1985)
  10.     All Rights Reserved.
  11.  
  12. ************************************************************/
  13.  
  14.  
  15. #ifndef __STDIO__
  16. #define __STDIO__
  17.  
  18. #define NULL 0
  19.  
  20. #ifndef __size_t__
  21. #define __size_t__
  22. typedef unsigned int size_t;
  23. #endif
  24.  
  25. #ifndef __va_list__
  26. #define __va_list__
  27. typedef char *va_list;
  28. #endif
  29.  
  30.  
  31. /*
  32.  *    The basic data structure for a stream is the FILE.
  33.  */
  34.  
  35. typedef struct {
  36.     int             _cnt;
  37.     unsigned char    *_ptr;
  38.     unsigned char    *_base;
  39.     unsigned char    *_end;
  40.     unsigned short    _size;
  41.     unsigned short    _flag;
  42.     unsigned short    _file;
  43. } FILE;
  44.  
  45.  
  46. /*
  47.  *    fpos_t is a type that can express any position in a file.  A file's
  48.  *    end-of-file marker has type fpos_t.
  49.  */
  50.  
  51. typedef long fpos_t;
  52.  
  53.  
  54. /*
  55.  *    These macros give the meanings of bits in a FILE's _flag.  setvbuf() takes
  56.  *    one of _IOFBF, _IOLBF, or _IONBF as its third argument.
  57.  */
  58.  
  59. #define _IOFBF        0            /* Pseudo-flag, default buffering style */
  60. #define _IOREAD     (1<<0)        /* Current mode is for reading */
  61. #define _IOWRT        (1<<1)        /* Current mode is for writing */
  62. #define _IONBF        (1<<2)        /* no buffering */
  63. #define _IOMYBUF    (1<<3)        /* buffer was allocated by stdio */
  64. #define _IOEOF        (1<<4)
  65. #define _IOERR        (1<<5)
  66. #define _IOLBF        (1<<6)        /* fflush(iop) when a \n is written */
  67. #define _IORW        (1<<7)        /* Enable read/write access */
  68. #define _IOSYNC        (1<<8)        /* Input triggers fflush() to output fp's */
  69. #define _IOBINARY    (1<<9)        /* Binary stream */
  70.  
  71.  
  72. /*
  73.  *    Default file buffer sizes used by setbuf() and setvbuf().
  74.  */
  75.  
  76. #define BUFSIZ    1024            /* default file buffer size */
  77. #define _LBFSIZ  100            /* Line buffer size */
  78.  
  79.  
  80. /*
  81.  *    The standard end-of-file indicator.
  82.  */
  83.  
  84. #define EOF        (-1)
  85.  
  86.  
  87. /*
  88.  *    L_tmpnam is the size of char array long enough to hold a temporary file name
  89.  *    generated by tmpnam(), including the trailing null byte.  The name is in the
  90.  *    form tmp.AAAXXXXXX, where AAA is a sequence of lower case letters ("aaa", "baa",
  91.  *    ... "zzz" on successive calls), and XXXXXX is a lower case letter followed by a sequence
  92.  *    of digits, all determined at runtime.
  93.  *    TMP_MAX is the number of distinct file names that tmpnam() can generate.
  94.  */
  95.  
  96. #define L_tmpnam    14
  97. #define TMP_MAX        17576
  98.  
  99.  
  100. /*
  101.  *    The minimum number of files that a program is guaranteed to be able to have
  102.  *    open simultaneously (including the pre-opened stdin, stdout, and stderr).
  103.  *    The numbers are listed in Inside Macintosh, page IV-178, as:
  104.  *    64K ROM, 128K Macintosh        12 files
  105.  *    64K ROM, 512K Macintosh        40 files
  106.  *    128K ROM                    40 files per volume
  107.  */
  108.  
  109. #define FOPEN_MAX    12
  110.  
  111.  
  112. /*
  113.  *    Maximum length of a file name, including a trailing zero byte.
  114.  */
  115.  
  116. #define FILENAME_MAX    32
  117.  
  118.  
  119. /*
  120.  *    For use by fseek():
  121.  */
  122.  
  123. #ifndef __FCNTL__            /* these defns exactly paralled in FCntl.h for lseek() */
  124.  
  125. #define SEEK_CUR    1
  126. #define SEEK_END    2
  127. #define SEEK_SET    0
  128. #endif
  129.  
  130.  
  131. /*
  132.  *    The standard predefined streams.
  133.  */
  134.  
  135. #define stdin        (&_iob[0])
  136. #define stdout        (&_iob[1])
  137. #define stderr        (&_iob[2])
  138.  
  139.  
  140. #ifdef __cplusplus
  141. extern "C" {
  142. #endif
  143.  
  144. /*
  145.  *    Operations on files
  146.  */
  147.  
  148. int remove(const char *filename);
  149. int rename(const char *oldname, const char *newname);
  150. FILE *tmpfile(void);
  151. char *tmpnam(char *s);
  152.  
  153.  
  154. /*
  155.  *    File access functions
  156.  */
  157.  
  158. int fclose(FILE *stream);
  159. int fflush(FILE *stream);
  160. FILE *fopen(const char *filename, const char *mode);
  161. FILE *freopen(const char *filename, const char *mode, FILE *stream);
  162. void setbuf(FILE *stream, char *buf);
  163. int setvbuf(FILE *stream, char *buf, int mode, size_t size);
  164.  
  165.  
  166. /*
  167.  *    Formatted input/output functions
  168.  */
  169.  
  170. int fprintf(FILE *stream, const char *format, ...);
  171. int fscanf(FILE *stream, const char *format, ...);
  172. int printf(const char *format, ...);
  173. int scanf(const char *format, ...);
  174. int sprintf(char *s, const char *format, ...);
  175. int sscanf(const char *s, const char *format, ...);
  176. int vfprintf(FILE *stream, const char *format, va_list arg);
  177. int vprintf(const char *format, va_list arg);
  178. int vsprintf(char *s, const char *format, va_list arg);
  179.  
  180.  
  181. /*
  182.  *    Character input/output functions and macros
  183.  */
  184.  
  185. int fgetc(FILE *stream);
  186. char *fgets(char *s, int n, FILE *stream);
  187. int fputc(int c, FILE *stream);
  188. int fputs(const char *s, FILE *stream);
  189. int getc(FILE *stream);
  190. #define getc(p)     (--(p)->_cnt >= 0 ? (int) *(p)->_ptr++ : _filbuf(p))
  191. int getchar(void);
  192. #define getchar()    getc(stdin)
  193. char *gets(char *s);
  194. int putc(int c, FILE *stream);
  195. #define putc(x, p)    (--(p)->_cnt >= 0 ? \
  196.                         ((int) (*(p)->_ptr++ = (unsigned char) (x))) : \
  197.                         _flsbuf((unsigned char) (x), (p)))
  198. int putchar(int c);
  199. #define putchar(x)    putc((x), stdout)
  200. int puts(const char *s);
  201. int ungetc(int c, FILE *stream);
  202.  
  203.  
  204. /*
  205.  *    Direct input/output functions
  206.  */
  207.  
  208. size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
  209. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
  210.  
  211.  
  212. /*
  213.  *    File positioning functions
  214.  */
  215.  
  216. int fgetpos(FILE *stream, fpos_t *pos);
  217. int fseek(FILE *stream, long int offset, int whence);
  218. int fsetpos(FILE *stream, const fpos_t *pos);
  219. long int ftell(FILE *stream);
  220. void rewind(FILE *stream);
  221.  
  222.  
  223. /*
  224.  *    Error-handling functions and macros
  225.  */
  226.  
  227. void clearerr(FILE *stream);
  228. #define clearerr(p) ((void)((p)->_flag &= ~(_IOERR | _IOEOF)))
  229. int feof(FILE *stream);
  230. #define feof(p)     ((p)->_flag & _IOEOF)
  231. int ferror(FILE *stream);
  232. #define ferror(p)    ((p)->_flag & _IOERR)
  233. void perror(const char *s);
  234.  
  235. /*
  236.  * For macros
  237.  */
  238.  
  239. extern FILE _iob[];
  240. #define _NFILE 20
  241. int _filbuf(FILE *);
  242. int _flsbuf(int, FILE *);
  243.  
  244. /*
  245.  *    Non-ANSI extensions
  246.  */
  247.  
  248. #ifndef __STDC__
  249.  
  250. #define fileno(p)    (p)->_file
  251. FILE *fdopen(int fildes, const char *mode);
  252. void fsetfileinfo (char *filename, unsigned long newcreator, unsigned long newtype);
  253. int getw(FILE *stream);
  254. int putw(int w, FILE *stream);
  255.  
  256. #endif
  257.  
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261.  
  262.  
  263. #endif
  264.